package LeetcodeTest_thirty_one;
//922.按奇偶数组排序
public class sortArrayByParityII
{
    public static void main(String[] args)
    {
        int[] A={4,2,5,7};
        A=Solution.sortArrayByParityII(A);
        for(Integer value:A)
            System.out.println(value);
    }
}
class Solution
{
    public static int[] sortArrayByParityII(int[] A)
    {
        int i,j;
        int[] B=new int[A.length];
        for(i=0;i<A.length;i++)
        {
            B[i]=isEqual(i,A);
        }
        for(i=0;i<B.length-1;i++)
        {
            if(B[i]!=0)
            {
                for (j = i + 1; j < B.length; j++)
                {
                    if(B[i]+B[j]==0)
                    {
                        int temp=A[i];
                        A[i]=A[j];
                        A[j]=temp;
                    }
                }
            }
        }
        return A;
    }
    public static int isEqual(int index,int[] A)
    {
        if(A[index]%2==0 && index%2!=0)
            return 1;
        else if (A[index]%2!=0 && index%2==0)
            return -1;
        else
            return 0;
    }
}